﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Empolyee_bulu :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            var empolyee = new EmpolyeeBLL().GetEmpolyeeInfoByEmpolyeeID( new EmpolyeeBLL().GetEmpolyeeInfoByLoginName(Page.User.Identity.Name).EmpolyeeID);
            if (empolyee.Expansion != null && (!string.IsNullOrEmpty(empolyee.Expansion.IdCard) || !string.IsNullOrEmpty(empolyee.Expansion.Address)))
            {
                Button1.Visible = false;
                AlterAndRedirect("已经补录，无需再次补录", "../default.aspx");
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        var empolyee = new EmpolyeeBLL().GetEmpolyeeInfoByLoginName(Page.User.Identity.Name);
        empolyee.Expansion = new EmpolyeeInfoExpansion();

        empolyee.Expansion.Address = txtUserAddress.Text.Trim();
        try
        {
            empolyee.Expansion.Birthday = DateTime.Parse(txtUserBirthday.Text.Trim());
        }
        catch (Exception)
        {
            AlertMsg("生日格式错误");
            return;
        }
        empolyee.Expansion.IdCard = txtUserIdCard.Text.Trim();
        empolyee.Expansion.Phone = txtUserPhone.Text.Trim();
        empolyee.Expansion.Sex = Convert.ToInt32(DropDownList1.SelectedValue);

        try
        {
            if (new EmpolyeeBLL().UpdateEmpolyee(empolyee))
            {
                AlterAndRedirect("补录信息成功", "../default.aspx");
            }
            else
            {
                AlertMsg("注册失败，请联系管理员");
            }
        }
        catch (Exception ex)
        {
            AlertMsg(ex.Message);
        }
    }
}